package com.yzy.controller;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yzy.demo.Progress;
import com.yzy.demo.ProgressList;
import com.yzy.demo.Service;
import com.yzy.service.CpuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class CpuController {
    @Autowired
    public CpuService cpuService;
    @ResponseBody
    @GetMapping(value = "/myGet")
    public ArrayList<Progress> myGet(String myName1,String myName2,String myName3,String myName4,String myName5,String myName6,String myName7,
                                      String myArriveTime1,String myArriveTime2,String myArriveTime3,String myArriveTime4,String myArriveTime5,String myArriveTime6,String myArriveTime7,
                                      String myRunTime1,String myRunTime2,String myRunTime3,String myRunTime4,String myRunTime5,String myRunTime6,String myRunTime7,String myA){
        System.out.println(myA);
        if (myA==null){
            ArrayList<Progress>  NullList =new ArrayList<Progress>();
            NullList.add(new Progress(null,0,0));
            return NullList;
        }
        ArrayList<Progress> FCFSList = cpuService.myFCFS(myName1,myName2,myName3,myName4,myName5,myName6, myName7,
                myArriveTime1,myArriveTime2, myArriveTime3,myArriveTime4,myArriveTime5, myArriveTime6, myArriveTime7,
                 myRunTime1,myRunTime2,myRunTime3,myRunTime4, myRunTime5, myRunTime6, myRunTime7);

        ArrayList<Progress> SJFList = cpuService.mySJF(myName1,myName2,myName3,myName4,myName5,myName6, myName7,
                myArriveTime1,myArriveTime2, myArriveTime3,myArriveTime4,myArriveTime5, myArriveTime6, myArriveTime7,
                myRunTime1,myRunTime2,myRunTime3,myRunTime4, myRunTime5, myRunTime6, myRunTime7);
        /*System.out.println("先到先服务的执行过程：");
        for(Progress p:FCFSList) {
            System.out.println(p);
        }*/

       /*ObjectMapper mapper =new ObjectMapper();
        JsonResult = null;
        try {
            JsonResult = mapper.writeValueAsString(progressList);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        System.out.println(JsonResult);*/
       // String jsonString = JSON.toJSONString(progressList);
        // map.put("myJson",json);
        if (myA.equals("FCFS")){
            return FCFSList;
        }else {
            return SJFList;
        }

    }

}
